﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevLegancy.XmlContent;
using DevLegancy.Models;
using DevLegancy.Data;
using System.Xml;
using System.Xml.Linq;
using System.Object ;

namespace DevLegancy.Bussines
{
    /// <summary>
    /// Bussiness Content Manager
    /// </summary>
    public class BussinesManager
    {
        #region Variables

        ContentManager _cm = new ContentManager();

        #endregion

        #region XmlFiles

        /// <summary>
        /// Carga los archivos
        /// </summary>
        public Dictionary<string, string> XmlContentGetAll()
        {
            return _cm.GetAll();
        }

        #endregion

        #region Contactos

        /// <summary>
        /// Función que guarda la información en la tabla de contactos
        /// </summary>
        /// <param name="contactoModel">Modelo de Contato</param>
        public void GuardarContacto(ContactoModel contactoModel)
        {
            try
            {
                Mailer.Mailer mailer = new Mailer.Mailer();
                DataAccess data = new DataAccess();
                bool isOk = data.GuardarContacto(contactoModel);
                if (isOk)
                {
                    XElement element = XElement.Load("C:/Users/Erika/Documents/Visual Studio 2012/Projects/Hades(Final)/DevLegancy.Mailer/MailContent.xml");
                    string asunto = element.Elements().Select(x => x.Attribute("Asunto").Value).ToString();
                    string body = element.Elements().Select(x => x.Attribute("Body").Value).ToString();

                    
                    bool isSended = mailer.EnviarEmailCliente(contactoModel.Email, "sebastianmartinez18@yahoo.com.co","", asunto, body, "");
                }
            }
            catch (Exception)
            {
                ///TODO: capturar la excepcion preguntar a Andres
                throw;
            }
        }
        #endregion

    }
}
